package com.youyou.fusheng2.View.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.youyou.fusheng2.Moudle.OnClick2;
import com.youyou.fusheng2.R;

import java.util.List;
import java.util.Map;

/**
 * @name fusheng2
 * @class name：com.youyou.fusheng2.View.Adapter
 * @anthor 浮生 QQ:2567294605
 * @time 2020/8/25 02:34
 * @to 搜索页面底部的九宫格
 */
public class VdioPagerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<Map<String, String>> typeTestLists;
    private OnClick2                  onClick;

    public VdioPagerAdapter(List<Map<String, String>> typeTestLists, OnClick2 onClick) {
        this.typeTestLists = typeTestLists;
        this.onClick= onClick;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.sousuo_recitem, parent, false);
        return new SouSuoItem1(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        Glide.with(holder.itemView.getContext())
                .load(typeTestLists.get(position).get("pic"))
                .into(((SouSuoItem1) holder).home_image);
        ((SouSuoItem1) holder).home_text.setText(typeTestLists.get(position).get("tname"));
        ((SouSuoItem1) holder).home_image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onClick.listener1(1, String.valueOf(position),position);
            }
        });
    }

    @Override
    public int getItemCount() {
        /**
         *  @作者: $浮生-qq:2567294605$
         *  @时间: 2020/8/26  15:05
         *  @简介: 如果集合为空就返回0 否则就加载集合的长度
         *  如果集合的长度不为9 就返回9
         */
        return typeTestLists.isEmpty()?0:9;
    }

    private class SouSuoItem1 extends RecyclerView.ViewHolder {

        private ImageView home_image;
        private TextView  home_text;

        public SouSuoItem1(View inflate) {
            super(inflate);
            home_image = inflate.findViewById(R.id.home_image);
            home_text = inflate.findViewById(R.id.home_text);
        }
    }
}
